package com.dha.caodangcongnghe;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dha.status.NetworkStatus;
import com.dha.ultility.QuangCao;
import com.dha.variable.ThongTinTaiKhoan;

public class GiaoVienDaDangNhap extends ActionBarActivity implements
		android.view.View.OnClickListener {
	private TextView tv_daDangNhap_giaoVien_hoTen;
	private NetworkStatus networkStatus;

	private ImageView iv_TB, iv_TKB, iv_GTB, iv_XD, iv_DX;
	private TextView tv_TB, tv_TKB, tv_GTB, tv_XD, tv_DX;

	// private QuangCao quangCao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_giaovien_dadangnhap);

		iv_TB = (ImageView) findViewById(R.id.iv_TB);
		iv_TB.setOnClickListener(this);

		iv_TKB = (ImageView) findViewById(R.id.iv_TKB);
		iv_TKB.setOnClickListener(this);

		iv_GTB = (ImageView) findViewById(R.id.iv_GTB);
		iv_GTB.setOnClickListener(this);

		iv_XD = (ImageView) findViewById(R.id.iv_XD);
		iv_XD.setOnClickListener(this);

		iv_DX = (ImageView) findViewById(R.id.iv_DX);
		iv_DX.setOnClickListener(this);

		tv_TB = (TextView) findViewById(R.id.tv_TB);
		tv_TB.setOnClickListener(this);

		tv_TKB = (TextView) findViewById(R.id.tv_TKB);
		tv_TKB.setOnClickListener(this);

		tv_GTB = (TextView) findViewById(R.id.tv_GTB);
		tv_GTB.setOnClickListener(this);

		tv_XD = (TextView) findViewById(R.id.tv_XD);
		tv_XD.setOnClickListener(this);

		tv_DX = (TextView) findViewById(R.id.tv_DX);
		tv_DX.setOnClickListener(this);

		// quangCao = new QuangCao(this, GiaoVienDaDangNhap.this);

		tv_daDangNhap_giaoVien_hoTen = (TextView) findViewById(R.id.tv_daDangNhap_giaoVien_hoTen);
		tv_daDangNhap_giaoVien_hoTen.setText(ThongTinTaiKhoan.hoTen);

		networkStatus = new NetworkStatus(getBaseContext());

	}
	@Override
	public void onBackPressed() {
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_TB:
		case R.id.tv_TB:
			if (networkStatus.isConnected()) {
				Intent intentThongBao = new Intent(getBaseContext(),
						XemThongBao.class);
				startActivity(intentThongBao);
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		case R.id.tv_TKB:
		case R.id.iv_TKB:
			if (networkStatus.isConnected()) {
				Intent intentXemTKB = new Intent("XemThoiKhoaBieu");
				intentXemTKB.putExtra("MaSo", ThongTinTaiKhoan.maTaiKhoan);
				startActivity(intentXemTKB);
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		case R.id.iv_GTB:
		case R.id.tv_GTB:
			if (networkStatus.isConnected()) {
				Intent intentDangThongBao = new Intent("GiaoVienDangThongBao");
				startActivity(intentDangThongBao);
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		case R.id.iv_XD:
		case R.id.tv_XD:
			// get layouy_dianlog_nha_ma_so_sinh_vien
			LayoutInflater inflater2 = LayoutInflater.from(this);
			View nhapMaSinhVienView2 = inflater2.inflate(
					R.layout.layout_dialog_nhap_ma_so_sinh_vien, null);

			AlertDialog.Builder alertBuilder2 = new AlertDialog.Builder(this);
			// // set layouy_dianlog_nha_ma_so_sinh_vien.xml to alertdialog
			// builder
			alertBuilder2.setView(nhapMaSinhVienView2);

			final EditText et_maSinhVien2 = (EditText) nhapMaSinhVienView2
					.findViewById(R.id.et_layout_nhapMaSinhVien);

			// set dialog message

			alertBuilder2.setCancelable(false)
					.setNegativeButton("OK", new OnClickListener() {
						// Xu ly nut ok
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// set null gia tri Ten sinh vien
							ThongTinTaiKhoan.hoTenSinhVien = null;
							ThongTinTaiKhoan.maSinhVien = null;
							// neu nhap so khac 12 chu so ==> thong bao loi
							if (et_maSinhVien2.getText().length() == 12) {
								if (networkStatus.isConnected()) {
									// set gia tri vao masinh vien
									ThongTinTaiKhoan.maSinhVien = et_maSinhVien2
											.getText().toString();

									// Goi inten xem diem
									Intent itentGiaoVienXemDiem = new Intent(
											"GiaoVienXemDiemSinhVien");
									startActivity(itentGiaoVienXemDiem);
								} else {
									Intent intentLoi = new Intent(
											"SuCoVeKetNoiMang");
									startActivity(intentLoi);
								}
							} else {
								Toast.makeText(getBaseContext(),
										"Mã sinh viên 12 kí tự",
										Toast.LENGTH_SHORT).show();
							}

						}
					}).setPositiveButton("Thoát ra", new OnClickListener() {
						// Xu ly nut nhap lai
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
						}
					}).setTitle("Nhập mã số sinh viên");

			// create alert dialog
			AlertDialog alertDialog2 = alertBuilder2.create();

			// show it
			alertDialog2.show();
			break;
		case R.id.tv_DX:
		case R.id.iv_DX:
			finish();
			break;
		}
	}

}
